package com.wx.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wx.dao.CheckItemDao;
import com.wx.entity.PageResult;
import com.wx.entity.QueryPageBean;
import com.wx.pojo.CheckItem;
import com.wx.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImp implements CheckItemService {
    @Autowired
    private CheckItemDao checkItemDao;
    @Override
    public void add(CheckItem checkItem) {
        // 调用dao层方法
        System.out.println("远程访问到达");
        checkItemDao.add(checkItem);
    }

    @Override
    public PageResult queryPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        // 使用pageHelper分页查询
        PageHelper.startPage(currentPage,pageSize);

        // 进行查询
        List<CheckItem> checkItems = checkItemDao.pageQuery(queryString);
        PageInfo<CheckItem> info = new PageInfo<>(checkItems);
        // 返回查询结果
        long total = info.getTotal();
        PageResult pageResult = new PageResult(total, checkItems);

        return pageResult;

    }

    /**
     * 依据id查询检查项
     * @param id
     * @return
     */
    @Override
    public CheckItem pageUpdate(Integer id) {

        CheckItem checitemById = checkItemDao.findChecitemById(id);
        return checitemById;

    }

    @Override
    public void update(CheckItem checkItem) {

            checkItemDao.updateCheckitem(checkItem);
    }

    @Override
    public void deleteCheckitem(Integer id) {
        checkItemDao.deleteCheckitem(id);
    }
}
